package com.chihsien.springcloud.servcie.impl;

import com.chihsien.springcloud.servcie.IMessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;


/**
 * @auther chihsien on 2021/5/31
 */
@EnableBinding(Source.class)//给output指定通道 开启绑定器 作为消息生产者的发送管道的源
public class IMessageProviderImpl implements IMessageProvider {
    @Resource
    private MessageChannel output;//消息发送管道

    @Override
    public String send() {
        //定义一个流水号当作消息
        String serial = UUID.randomUUID().toString();
        //给Output管道绑定消息 MessageBuilder：消息构建器 withPayload 将消息丢进去build构建
        output.send(MessageBuilder.withPayload(serial).build());
        System.out.println("------" + serial);
        return null;
    }
}
